package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page page = nursingProjectMapper.queryPage(name,status);
        return PageResponse.of(page, NursingProjectVo.class);
    }

    @Override
    public void add(NursingProjectDto nursingProjectDto) {
//        NursingProject nursingProject = new NursingProject();
//        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        /*nursingProject.setCreateBy(1l);
        nursingProject.setUpdateBy(1l);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());*/
        nursingProjectMapper.add(nursingProject);
    }

    @Override
    public NursingProjectVo getById(Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectMapper.getById(id);
        return nursingProjectVo;
    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
//        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
//        nursingProject.setStatus(0);
//        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void OnOrNot(Long id, Integer status) {
        nursingProjectMapper.OnOrNot(id,status);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.deleteProject(id);
    }

    @Override
    public List<NursingProjectVo> getAll() {
        return nursingProjectMapper.getAll();
    }
}

















